import 'package:get_storage/get_storage.dart';

class AppStorage {
  factory AppStorage() => _instance;
  static final AppStorage _instance = AppStorage._init();

  AppStorage._init();

  init() async {
    if (appStorage == null) {
      await GetStorage.init();
      appStorage = GetStorage();
    }
  }

  GetStorage? appStorage;

  dynamic readKey(String key) {  // key无值时为null
    return appStorage?.read(key);
  }

  Future<void> writeKey(String key, dynamic value) async {
    await appStorage?.write(key, value);
  }

  Future<void> removeKey(String key) async {
    await appStorage?.remove(key);
  }
}

class StorageKey {
  static const String token = 'token';
  static const String userId = 'userId';
  static const String phone = 'phone';
  static const String countryConfig = 'countryConfig';
  static const String activeDevice = 'activeDevice';
  static const String h5Version = 'h5Version';
}